package com.ssl.basics.thread;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.TimeUnit;

/**
 * 描述：join的意思是，其他线程需要等待当前线程执行完才能开始
 *
 * @author shi_senlin
 * @create 2021/07/10 12:10
 */
@Slf4j(topic = "com.ssl.thread")
public class ThreadJoin {

    public static void main(String[] args) throws InterruptedException {
        Thread t1 = new Thread(()->{
            try {
                log.info("{} 线程启动...",Thread.currentThread().getName());
                TimeUnit.SECONDS.sleep(1);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        },"t1");

        Thread t2 = new Thread(()->{
            try {
                log.info("{} 线程启动...",Thread.currentThread().getName());
                TimeUnit.SECONDS.sleep(2);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        },"t2");

        t1.start();
        // t1.join();
        t2.start();
        t2.join();
        t1.join();

        log.info("所有线程结束...");

    }
}
